$(function () {
  //表单验证
  layui.form.verify({
    pwd: [/^[\S]{6,12}$/, "密码必须6到12位，且不能出现空格"],
    diffPwd: function (value, item) {
      if (value == $("[name=oldPwd]").val()) {
        return "新旧密码不能一致！";
      }
    },
    rePwd: function (value, item) {
      if (value != $("[name=newPwd]").val()) {
        return "两次密码不一致！";
      }
    },
  });

  //发送请求
  $("#form1").submit(function (e) {
    e.preventDefault();
    $.ajax({
      type: "post",
      url: "/my/updatepwd",
      data: $(this).serialize(),
      success(res) {
        layui.layer.msg(res.message);
        if (res.status) return;
        localStorage.removeItem("token");
        window.parent.location.href = "/login.html";
      },
    });
  });
});
